home *** CD-ROM | disk | FTP | other *** search
- /***
- *** Light Speed Graphics Programming Library
- ***
- *** Simple demonstration program
- ***
- *** Compiled under Turbo C v2.01 - modifications needed for
- *** other compilers.
- ***/
-
- /* The Light Speed Header File */
- #include "lspeed.h"
-
- /* Memory allocation header file */
- #include <alloc.h>
-
- /* Time functions */
- #include <dos.h>
-
- /* Random numbers */
- #include <stdlib.h>
-
- /* Closing text */
- #include <conio.h>
-
- /* The font name variables */
- char *fontstyles[] = {
- "Broad Text", "Computer Text",
- "Plasma Display", "EGA Small Font",
- "EGA Standard", "Tall Text",
- "Script Flow", "Nice Font",
- "Crisp Character", "Old English",
- "Plain Text", "Italic Font" };
-
- /* Function declarations */
- void title(void);
- void fonts(void);
- void demonstrate_font(int font);
- void images(void);
- void primitives(void);
- void demo_line(void);
- void demo_triangle(void);
- void demo_ftriangle(void);
- void demo_rectangle(void);
- void demo_circle(void);
- void putcircle(int xloc, int yloc, int radius, int colour);
- void demo_fcircle(void);
- void demo_ellipse(void);
- void putellipse(int xloc, int yloc, int radius1, int radius2, int colour);
- void demo_fellipse(void);
- void demo_pixels(void);
- void demo_polygon(void);
-
- /* Main function */
- main()
- {
- /* Setup graphics mode */
- set640x350();
-
- /* Pass control over to each of the functions in turn... */
-
- /* Title screen */
- title();
-
- /* Font styles */
- fonts();
-
- /* Image manipulation system */
- images();
-
- /* Demonstrate some of the primitives */
- primitives();
-
- /* In closing... */
- set80x25();
- cprintf("Well, you've seen demos of just SOME of the Light Speed functions...\n\r");
- cprintf("Now, you can use that power in your own applications!!!\n\r");
- cprintf("Get stuck into it!!\n\r");
- cprintf("\n\rOh yeah - register and receive the benefits - do it now!\n\r");
- }
-
- /* Draw up the title screen */
- void title(void)
- {
- /* Variables */
- struct time current, old;
-
- /* Set for hidden page load */
- ega_setapage(2);
- ega_setvpage(1);
-
- /* Load in the 'LYONWARE' screen image */
- ega_restore_screen_byte("logo.scr");
-
- /* Show the screen */
- ega_setvpage(2);
-
- /* Load in the 'LIGHT SPEED' screen image */
- ega_setapage(1);
- ega_restore_screen_byte("lspd.scr");
- ega_setapage(2);
- ega_filledrectangle(0,0,639,349,15);
- ega_setvpage(1);
-
- /* Wait for either time or keypress */
- gettime(&old);
- while (!kbhit())
- {
- gettime(¤t);
- if (current.ti_sec>old.ti_sec+4)
- break;
- }
- if (kbhit()) /* Get the key if there is one */
- getxch();
- }
-
- /* Font style demonstrations */
- void fonts(void)
- {
- /* Variables */
- int loop;
-
- /* Clear the screen */
- set640x350();
-
- /* Register all fonts */
- registerbroadfont();
- registercomputerfont();
- registertallfont();
- registersmallfont();
- registerscriptfont();
- registerplasmafont();
- registerplainfont();
- registeroldenglishfont();
- registernicefont();
- registeritalicfont();
- registerstandardfont();
- registercrispfont();
-
- /* What we are doing */
- ega_writetext(10, 10, LS_WHITE, LS_BLACK, NICE_FONT,
- "First up, is the flexible font system!");
- ega_writetext(10, 25, LS_WHITE, LS_BLACK, NICE_FONT,
- "All 12 of the available fonts will be demonstrated!");
- ega_writetext(10, 50, LS_WHITE, LS_BLACK, NICE_FONT,
- "Press a key to proceed to the demo...");
- getxch();
-
- /* Loop through all twelve fonts */
- for (loop=1; loop<=12; loop++)
- demonstrate_font(loop);
- }
-
- /* DEMONSTRATE_FONT - called with the value of the font to use, */
- /* this function will provide several */
- /* graphics mode ouput tests. */
- void demonstrate_font(font)
- int font;
- {
- /* Variables */
- int foreloop, backloop;
-
- /* Clear the graphics screen */
- ega_clearpage();
-
- /* Tell the user the font we are displaying */
- ega_formattext(10, 10, LS_YELLOW, LS_BLACK, STANDARD_FONT,
- "Demonstrating %s!", fontstyles[font-1]);
-
- /* Print out the standard alphabet in the text style */
- ega_writetext(20, 30, LS_WHITE, LS_BLACK, font,
- "The standard character set:");
- ega_formattext(25, 30+ega_fontheight(font), LS_CYAN, LS_BLACK, font,
- " !%c#$%&'()*+,-./0123456789:;<=>?@", 34);
- ega_writetext(25, 30+ega_fontheight(font)*2, LS_CYAN, LS_BLACK, font,
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`");
- ega_writetext(25, 30+ega_fontheight(font)*3, LS_CYAN, LS_BLACK, font,
- "abcdefghijklmnopqrstuvwxyz{|}~");
-
- /* Tell a bit more about the text system */
- ega_writetext(15, 120, LS_YELLOW, LS_BLACK, font,
- "The above is only a demonstration of the font...");
- ega_writetext(15, 120+ega_fontheight(font), LS_YELLOW, LS_BLACK, font,
- "The real power lies in foreground/background colours!");
- for (foreloop=0; foreloop<=15; foreloop++)
- for (backloop=0; backloop<=7; backloop++)
- ega_writetext(30+foreloop*32, 160+backloop*ega_fontheight(font),
- foreloop, backloop, font, " WOW ");
-
- /* Write a message and wait for the next keypress */
- ega_writetext(15, 320, LS_WHITE, LS_BLUE, STANDARD_FONT,
- " Press any key to continue... ");
- getxch();
- }
-
- /* Demonstrate the image manipulation routines */
- void images(void)
- {
- /* Variables */
- int loop, xloc, yloc;
- unsigned char image;
- unsigned int key;
- char far *heli1, far *heli2, far *heli3, far *heli4;
-
- /* Set graphics */
- set320x200();
-
- /* Write a 'wait' message */
- ega_writetext(10, 10, LS_YELLOW, LS_BLACK, STANDARD_FONT,
- "Next up is the powerful image system!");
- ega_writetext(10, 20, LS_YELLOW, LS_BLACK, STANDARD_FONT,
- "These graphics are from part of a game");
- ega_writetext(10, 30, LS_YELLOW, LS_BLACK, STANDARD_FONT,
- "I am working on! (Using Light Speed)");
- ega_writetext(10, 45, LS_YELLOW, LS_BLACK, STANDARD_FONT,
- "Please wait, loading data...");
-
- /* Allocate data for the images */
- heli1=farmalloc(ega_imagesize(0,0,46,40));
- heli2=farmalloc(ega_imagesize(0,0,46,40));
- heli3=farmalloc(ega_imagesize(0,0,46,40));
- heli4=farmalloc(ega_imagesize(0,0,46,40));
-
- /* Check for any that didn't allocate */
- if (heli1==NULL || heli2==NULL || heli3==NULL || heli4==NULL)
- {
- /* De-allocate all images */
- farfree(heli1); farfree(heli2);
- farfree(heli3); farfree(heli4);
- set80x25();
- printf("Did not have enough memory to load data!\n");
- exit(1);
- }
-
- /* Load into the hidden page */
- ega_setapage(2);
- if (ega_restore_area_byte("heli.img",0,0,187,37,0,2)==-2)
- {
- farfree(heli1); farfree(heli2);
- farfree(heli3); farfree(heli4);
- set80x25();
- printf("Could not find 'HELI.IMG' image file...\n");
- exit(1);
- }
-
- /* Save the images */
- ega_getimage( 0, 0, 46, 40, heli1);
- ega_getimage( 47, 0, 93, 40, heli2);
- ega_getimage( 94, 0,140, 40, heli3);
- ega_getimage(141, 0,187, 40, heli4);
-
- /* Enough time to read message */
- ega_setapage(1);
- ega_writetext(10, 45, LS_YELLOW, LS_BLACK, STANDARD_FONT,
- "Press a key to continue... ");
- getxch();
-
- /* Clear all pages */
- set320x200();
-
- /* Write instructions */
- ega_writetext(0, 0, LS_WHITE, LS_BLACK, STANDARD_FONT,
- "Use cursor keys to control, Esc to stop");
-
- /* Variables setup */
- image=0;
- xloc=150;
- yloc=75;
-
- /* Loop */
- loop:
- if (kbhit())
- key=getxch(); /* Key available */
- else
- key=0; /* No key */
-
- /* ESC aborts */
- if (key==0x011B)
- {
- farfree(heli1); farfree(heli2);
- farfree(heli3); farfree(heli4);
- return;
- }
-
- /* Test for directions */
- switch (key)
- {
- case 0x4800 : /* UP */
- yloc--; yloc--;
- if (yloc<10)
- yloc=10;
- break;
- case 0x4900 : /* UP-RIGHT */
- yloc--; yloc--;
- if (yloc<10)
- yloc=10;
- xloc++; xloc++;
- if (xloc>272)
- xloc=272;
- break;
- case 0x4700 : /* UP-LEFT */
- yloc--; yloc--;
- if (yloc<10)
- yloc=10;
- xloc--; xloc--;
- if (xloc<0)
- xloc=0;
- break;
- case 0x5000 : /* DOWN */
- yloc++; yloc++;
- if (yloc>161)
- yloc=161;
- break;
- case 0x5100 : /* DOWN-RIGHT */
- yloc++; yloc++;
- if (yloc>161)
- yloc=161;
- xloc++; xloc++;
- if (xloc>272)
- xloc=272;
- break;
- case 0x4F00 : /* DOWN-LEFT */
- yloc++; yloc++;
- if (yloc>161)
- yloc=161;
- xloc--; xloc--;
- if (xloc<0)
- xloc=0;
- break;
- case 0x4D00 : /* RIGHT */
- xloc++; xloc++;
- if (xloc>272)
- xloc=272;
- break;
- case 0x4B00 : /* LEFT */
- xloc--; xloc--;
- if (xloc<0)
- xloc=0;
- break;
- }
-
- /* Update image */
- image++;
-
- /* Draw correct image */
- if (image<7)
- ega_putimage(heli1, xloc, yloc);
- else if (image<14)
- ega_putimage(heli2, xloc, yloc);
- else if (image<21)
- ega_putimage(heli3, xloc, yloc);
- else if (image<28)
- ega_putimage(heli4, xloc, yloc);
- else
- image=0; /* Out of range - reset */
-
- /* Repeat cycle */
- goto loop;
- }
-
- /* Demonstrate some of the grpahics primitives */
- void primitives(void)
- {
- /* Set graphics mode */
- set640x350();
-
- /* What is going to happen */
- ega_writetext(10, 10, LS_WHITE, LS_BLACK, NICE_FONT,
- "The following series of demonstrations show you the flexibility of the");
- ega_writetext(10, 25, LS_WHITE, LS_BLACK, NICE_FONT,
- "graphics primitives. They are all in one long sequence... Just press");
- ega_writetext(10, 40, LS_WHITE, LS_BLACK, NICE_FONT,
- "a key to continue from one to the next!!!");
- ega_writetext(10, 60, LS_YELLOW, LS_BLACK, NICE_FONT,
- "Press a key now to start...");
- getxch();
-
- /* Line drawing */
- demo_line();
-
- /* Triangle drawing */
- demo_triangle();
-
- /* Filled triangle drawing */
- demo_ftriangle();
-
- /* Rectangle drawing */
- demo_rectangle();
-
- /* Circle drawing */
- demo_circle();
-
- /* Filled circle drawing */
- demo_fcircle();
-
- /* Ellipse drawing */
- demo_ellipse();
-
- /* Filled ellipse drawing */
- demo_fellipse();
-
- /* Pixel plotting */
- demo_pixels();
-
- /* Polygon drawing */
- demo_polygon();
- }
-
- /* Line drawing demonstration */
- void demo_line(void)
- {
- /* Variables */
- int lines[4][32], left_x_inc, right_x_inc, up_y_inc, down_y_inc;
- unsigned char curline;
-
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers, set variables */
- randomize();
- left_x_inc=-2;
- right_x_inc=2;
- up_y_inc=2;
- down_y_inc=2;
-
- /* Print the demonstration message */
- ega_writetext(132, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Line drawing demo! Press a key to continue... ");
-
- /* Set up some lines */
- lines[0][0] = 320;
- lines[1][0] = 170;
- lines[2][0] = 320;
- lines[3][0] = 170;
- for (curline=1; curline<32; curline++)
- {
- lines[0][curline] = lines[0][curline-1]+left_x_inc;
- lines[1][curline] = lines[1][curline-1]+up_y_inc;
- lines[2][curline] = lines[2][curline-1]+right_x_inc;
- lines[3][curline] = lines[3][curline-1]+down_y_inc;
- }
-
- /* Draw the lines */
- for (curline=0; curline<32; curline++)
- ega_putline(lines[0][curline], lines[1][curline],
- lines[2][curline], lines[3][curline], curline);
- curline=31;
-
- /* While there is no key... */
- while (!kbhit())
- {
- curline++;
-
- /* Erase the last line */
- ega_putline(lines[0][curline&31], lines[1][curline&31],
- lines[2][curline&31], lines[3][curline&31], 0);
-
- /* Increment the first point */
- lines[0][curline&31] = lines[0][(curline-1)&31]+left_x_inc;
- if (lines[0][curline&31]<0) /* Out of range? */
- {
- left_x_inc=random(11)+3;
- lines[0][curline&31]=0;
- }
- if (lines[0][curline&31]>639) /* Out of range? */
- {
- left_x_inc=-10+random(11)-3;
- lines[0][curline&31]=639;
- }
-
- /* Increment the second point */
- lines[1][curline&31] = lines[1][(curline-1)&31]+up_y_inc;
- if (lines[1][curline&31]<0) /* Out of range? */
- {
- up_y_inc=random(11)+3;
- lines[1][curline&31]=0;
- }
- if (lines[1][curline&31]>334) /* Out of range? */
- {
- up_y_inc=-10+random(11)-3;
- lines[1][curline&31]=334;
- }
-
- /* Increment the third point */
- lines[2][curline&31] = lines[2][(curline-1)&31]+right_x_inc;
- if (lines[2][curline&31]<0) /* Out of range? */
- {
- right_x_inc=random(11)+3;
- lines[2][curline&31]=0;
- }
- if (lines[2][curline&31]>639) /* Out of range? */
- {
- right_x_inc=-10+random(11)-3;
- lines[2][curline&31]=639;
- }
-
- /* Increment the last point */
- lines[3][curline&31] = lines[3][(curline-1)&31]+down_y_inc;
- if (lines[3][curline&31]<0) /* Out of range? */
- {
- down_y_inc=random(11)+3;
- lines[3][curline&31]=0;
- }
- if (lines[3][curline&31]>334) /* Out of range? */
- {
- down_y_inc=-10+random(11)-3;
- lines[3][curline&31]=334;
- }
-
- /* Draw the newly updated line */
- ega_putline(lines[0][curline&31], lines[1][curline&31],
- lines[2][curline&31], lines[3][curline&31], curline);
-
- /* Small microprocessor delay */
- delay(5);
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Triangle drawing demonstration */
- void demo_triangle(void)
- {
- /* Variables */
- int lines[6][16], first_x_inc, second_x_inc, first_y_inc;
- int second_y_inc, third_x_inc, third_y_inc;
- unsigned char curline;
-
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers, set variables */
- randomize();
- first_x_inc=0;
- second_x_inc=2;
- third_x_inc=-2;
- first_y_inc=-2;
- second_y_inc=2;
- third_y_inc=2;
-
- /* Print the demonstration message */
- ega_writetext(116, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Triangle drawing demo! Press a key to continue... ");
-
- /* Set first some lines */
- lines[0][0] = 320;
- lines[1][0] = 170;
- lines[2][0] = 320;
- lines[3][0] = 170;
- lines[4][0] = 320;
- lines[5][0] = 170;
-
- for (curline=1; curline<16; curline++)
- {
- lines[0][curline] = lines[0][curline-1]+first_x_inc;
- lines[1][curline] = lines[1][curline-1]+first_y_inc;
- lines[2][curline] = lines[2][curline-1]+second_x_inc;
- lines[3][curline] = lines[3][curline-1]+second_y_inc;
- lines[4][curline] = lines[4][curline-1]+third_x_inc;
- lines[5][curline] = lines[5][curline-1]+third_y_inc;
- }
-
- /* Draw the lines */
- for (curline=0; curline<16; curline++)
- ega_puttriangle(lines[0][curline], lines[1][curline],
- lines[2][curline], lines[3][curline],
- lines[4][curline], lines[5][curline],
- curline&15);
- curline=15;
-
- /* While there is no key... */
- while (!kbhit())
- {
- curline++;
-
- /* Erase the last triangle */
- ega_puttriangle(lines[0][curline&15], lines[1][curline&15],
- lines[2][curline&15], lines[3][curline&15],
- lines[4][curline&15], lines[5][curline&15], 0);
-
- /* Increment the first point */
- lines[0][curline&15] = lines[0][(curline-1)&15]+first_x_inc;
- if (lines[0][curline&15]<0) /* Out of range? */
- {
- first_x_inc=random(11)+3;
- lines[0][curline&15]=0;
- }
- if (lines[0][curline&15]>639) /* Out of range? */
- {
- first_x_inc=-10+random(11)-3;
- lines[0][curline&15]=639;
- }
-
- /* Increment the second point */
- lines[1][curline&15] = lines[1][(curline-1)&15]+first_y_inc;
- if (lines[1][curline&15]<0) /* Out of range? */
- {
- first_y_inc=random(11)+3;
- lines[1][curline&15]=0;
- }
- if (lines[1][curline&15]>334) /* Out of range? */
- {
- first_y_inc=-10+random(11)-3;
- lines[1][curline&15]=334;
- }
-
- /* Increment the third point */
- lines[2][curline&15] = lines[2][(curline-1)&15]+second_x_inc;
- if (lines[2][curline&15]<0) /* Out of range? */
- {
- second_x_inc=random(11)+3;
- lines[2][curline&15]=0;
- }
- if (lines[2][curline&15]>639) /* Out of range? */
- {
- second_x_inc=-10+random(11)-3;
- lines[2][curline&15]=639;
- }
-
- /* Increment the fourth point */
- lines[3][curline&15] = lines[3][(curline-1)&15]+second_y_inc;
- if (lines[3][curline&15]<0) /* Out of range? */
- {
- second_y_inc=random(11)+3;
- lines[3][curline&15]=0;
- }
- if (lines[3][curline&15]>334) /* Out of range? */
- {
- second_y_inc=-10+random(11)-3;
- lines[3][curline&15]=334;
- }
-
- /* Increment the fifth point */
- lines[4][curline&15] = lines[4][(curline-1)&15]+third_x_inc;
- if (lines[4][curline&15]<0) /* Out of range? */
- {
- third_x_inc=random(11)+3;
- lines[4][curline&15]=0;
- }
- if (lines[4][curline&15]>639) /* Out of range? */
- {
- third_x_inc=-10+random(11)-3;
- lines[4][curline&15]=639;
- }
-
- /* Increment the last point */
- lines[5][curline&15] = lines[5][(curline-1)&15]+third_y_inc;
- if (lines[5][curline&15]<0) /* Out of range? */
- {
- third_y_inc=random(11)+3;
- lines[5][curline&15]=0;
- }
- if (lines[5][curline&15]>334) /* Out of range? */
- {
- third_y_inc=-10+random(11)-3;
- lines[5][curline&15]=334;
- }
-
- /* Draw the new triangle */
- ega_puttriangle(lines[0][curline&15], lines[1][curline&15],
- lines[2][curline&15], lines[3][curline&15],
- lines[4][curline&15], lines[5][curline&15],
- curline);
-
- delay(5);
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Filled triangle drawing */
- void demo_ftriangle(void)
- {
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers */
- randomize();
-
- /* Print the demonstration message */
- ega_writetext(88, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Filled triangle drawing demo! Press a key to continue... ");
-
- /* While there is no key... */
- while (!kbhit())
- {
- /* Draw a random triangle */
- ega_filledtriangle(random(640), random(335), random(640),
- random(335), random(640), random(335),
- random(16));
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Rectangle drawing demo */
- void demo_rectangle(void)
- {
- /* Variables */
- int lines[4][16], left_x_inc, right_x_inc, up_y_inc, down_y_inc;
- unsigned char curline;
-
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers, set variables */
- randomize();
- left_x_inc=-5;
- right_x_inc=5;
- up_y_inc=-5;
- down_y_inc=5;
-
- /* Print the demonstration message */
- ega_writetext(112, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Rectangle drawing demo! Press a key to continue... ");
-
- /* Set up some lines */
- lines[0][0] = 320;
- lines[1][0] = 170;
- lines[2][0] = 320;
- lines[3][0] = 170;
- for (curline=1; curline<16; curline++)
- {
- lines[0][curline] = lines[0][curline-1]+left_x_inc;
- lines[1][curline] = lines[1][curline-1]+up_y_inc;
- lines[2][curline] = lines[2][curline-1]+right_x_inc;
- lines[3][curline] = lines[3][curline-1]+down_y_inc;
- }
-
- /* Draw the lines */
- for (curline=0; curline<16; curline++)
- ega_putrectangle(lines[0][curline], lines[1][curline],
- lines[2][curline], lines[3][curline], curline);
- curline=15;
-
- /* While there is no key... */
- while (!kbhit())
- {
- curline++;
-
- /* Erase the last rectangle */
- ega_putrectangle(lines[0][curline&15], lines[1][curline&15],
- lines[2][curline&15], lines[3][curline&15], 0);
-
- /* Increment first point */
- lines[0][curline&15] = lines[0][(curline-1)&15]+left_x_inc;
- if (lines[0][curline&15]<0) /* Out of range? */
- {
- left_x_inc=random(11)+3;
- lines[0][curline&15]=0;
- }
- if (lines[0][curline&15]>639) /* Out of range? */
- {
- left_x_inc=-10+random(11)-3;
- lines[0][curline&15]=639;
- }
-
- /* Increment the second point */
- lines[1][curline&15] = lines[1][(curline-1)&15]+up_y_inc;
- if (lines[1][curline&15]<0) /* Out of range? */
- {
- up_y_inc=random(11)+3;
- lines[1][curline&15]=0;
- }
- if (lines[1][curline&15]>334) /* Out of range? */
- {
- up_y_inc=-10+random(11)-3;
- lines[1][curline&15]=334;
- }
-
- /* Increment the third point */
- lines[2][curline&15] = lines[2][(curline-1)&15]+right_x_inc;
- if (lines[2][curline&15]<0) /* Out of range? */
- {
- right_x_inc=random(11)+3;
- lines[2][curline&15]=0;
- }
- if (lines[2][curline&15]>639) /* Out of range? */
- {
- right_x_inc=-10+random(11)-3;
- lines[2][curline&15]=639;
- }
-
- /* Increment the last point */
- lines[3][curline&15] = lines[3][(curline-1)&15]+down_y_inc;
- if (lines[3][curline&15]<0) /* Out of range? */
- {
- down_y_inc=random(11)+3;
- lines[3][curline&15]=0;
- }
- if (lines[3][curline&15]>334) /* Out of range? */
- {
- down_y_inc=-10+random(11)-3;
- lines[3][curline&15]=334;
- }
- ega_putrectangle(lines[0][curline&15], lines[1][curline&15],
- lines[2][curline&15], lines[3][curline&15], curline);
-
- delay(15);
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Circle drawing demo */
- void demo_circle(void)
- {
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers */
- randomize();
-
- /* Print the demonstration message */
- ega_writetext(124, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Circle drawing demo! Press a key to continue... ");
-
- /* While there is no key... */
- while (!kbhit())
- {
- /* Place a random circle on the screen */
- putcircle(50+random(540), 50+random(235),
- random(50), random(16));
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Draw a circle 3 lines wide */
- void putcircle(xloc, yloc, radius, colour)
- int xloc, yloc;
- int radius;
- int colour;
- {
- if (radius<3)
- return;
- ega_putcircle(xloc, yloc, radius, colour);
- ega_putcircle(xloc, yloc, radius-1, colour);
- ega_putcircle(xloc, yloc, radius-2, colour);
- }
-
- /* Filled circles demo */
- void demo_fcircle(void)
- {
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers */
- randomize();
-
- /* Print the demonstration message */
- ega_writetext(96, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Filled circle drawing demo! Press a key to continue... ");
-
- /* While there is no key... */
- while (!kbhit())
- {
- /* Place a random circle on the screen */
- ega_filledcircle(50+random(535), 50+random(235), random(50),
- random(16));
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Ellipse drawing demo */
- void demo_ellipse(void)
- {
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers */
- randomize();
-
- /* Print the demonstration message */
- ega_writetext(120, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Ellipse drawing demo! Press a key to continue... ");
-
- /* While there is no key... */
- while (!kbhit())
- {
- /* Place a random ellipse on the screen */
- putellipse(50+random(540), 50+random(235),
- random(50), random(50), random(16));
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Draw an ellipse 3 lines wide */
- void putellipse(xloc, yloc, radius1, radius2, colour)
- int xloc, yloc;
- int radius1, radius2;
- int colour;
- {
- if (radius1<3 || radius2<3)
- return;
- ega_putellipse(xloc, yloc, radius1, radius2, colour);
- ega_putellipse(xloc, yloc, radius1-1, radius2-1, colour);
- ega_putellipse(xloc, yloc, radius1-2, radius2-2, colour);
- }
-
- /* Filled ellipse demo */
- void demo_fellipse(void)
- {
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers */
- randomize();
-
- /* Print the demonstration message */
- ega_writetext(92, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Filled ellipse drawing demo! Press a key to continue... ");
-
- /* While there is no key... */
- while (!kbhit())
- {
- /* Place a random ellipse on the screen */
- ega_filledellipse(50+random(540), 50+random(235), random(45)+5,
- random(45)+5, random(16));
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Pixel plotting demo */
- void demo_pixels(void)
- {
- /* Variables */
- int xloc, yloc, colour;
-
- /* Set the graphics mode, register font */
- set640x350();
- registernicefont();
-
- /* Seed the random numbers */
- randomize();
-
- /* Print the demonstration message */
- ega_writetext(124, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Pixel plotting demo! Press a key to continue... ");
-
- /* While there is no key... */
- while (!kbhit())
- {
- /* Place a random pixel on the screen */
- xloc = random(640);
- yloc = random(335);
- colour = random(16);
-
- /* Don't update already used locations */
- if (!ega_getpixel(xloc, yloc))
- ega_putpixel(xloc, yloc, colour);
- }
-
- /* Get the key */
- getxch();
- }
-
- /* Polygon drawing demo */
- void demo_polygon(void)
- {
- /* Variables */
- int locations[20][2], loop, looptop;
-
- /* Set the graphics mode */
- set640x350();
-
- /* Seed the random numbers */
- randomize();
-
- /* Print the demonstration message */
- ega_writetext(120, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
- " Polygon drawing demo! Press a key to continue... ");
-
- /* While there is no key... */
- while (!kbhit())
- {
- /* Place a random pixel on the screen */
- ega_putpoly(random(16), random(640), random(335), random(640),
- random(335), random(640), random(335), random(640),
- random(335), random(640), random(335), random(640),
- random(335), -1, -1);
-
- /* Small time delay */
- delay(125);
- }
-
- /* Get the key */
- getxch();
- }
-
-
-
-
-
-